//
//  XYMainTabBarController.swift
//  XYLive
//
//  Created by 赵正华 on 2017/4/17.
//  Copyright © 2017年 Z了个H. All rights reserved.
//

import UIKit

class XYMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setChilderViewController()
    }

}

extension XYMainTabBarController{

 
    fileprivate func setChilderViewController(){
    
        var childerArr = [UIViewController]()
        let arr = [
        
            ["clsName":"XYLiveController","title":"直播","image":"live"],
            ["clsName":"XYSortController","title":"排行","image":"sort"],
            ["clsName":"XYDiscoverController","title":"发现","image":"discover"],
            ["clsName":"XYMineController","title":"我的","image":"mine"],
        ]
        for dict in arr {
            childerArr.append(setChilderUI(dict: dict as [String:Any]))
        }
        viewControllers = childerArr
        
    }
    
    fileprivate func setChilderUI(dict:[String:Any])->UIViewController{
        
        guard let clsName = dict["clsName"] as? String,let clsTitle = dict["title"] as? String,let clsImage = dict["image"] as? String else {
            return UIViewController()
        }
        let cls = NSClassFromString(Bundle.main.nameSpace + "." + clsName) as? UIViewController.Type
        let vc = cls?.init()
        vc?.title = clsTitle
        vc?.tabBarItem.image = UIImage.init(named: clsImage)
        vc?.tabBarItem.selectedImage = UIImage.init(named: clsImage+"HL")
       vc?.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        vc?.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12)], for: .normal)
        let nav = XYMainNavController(rootViewController: vc!)
        return nav;
        
    }
}




